package com.chenu.gamscriptman.controller;

import com.chenu.gamscriptman.compoent.Global;
import com.chenu.gamscriptman.domain.Device;
import com.chenu.gamscriptman.domain.noindb.PageBean;
import com.chenu.gamscriptman.domain.noindb.Statistics;
import com.chenu.gamscriptman.service.impl.DeviceTaskImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

/**
 * @author flyan
 * date 2019-12-27
 * @function 设备控制器，它用于处理设备任务完成需要视图的服务后返回的回复消息
 */
@Controller
@ApiIgnore
public class DeviceController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private RedisTemplate jsonRedisTemplate;

    /**
     * 设备管理/列出所有用户
     */
    @GetMapping("/devices")
    public String users(
            Model model
    ){
        // 放入分页数据和查询参数
        PageBean<Device> device_page = (PageBean<Device>) jsonRedisTemplate.opsForValue().get(Global.REDIS_DEVICE_PAGES);
        model.addAttribute(Global.REDIS_DEVICE_PAGES, device_page);
        Device search_device = (Device) jsonRedisTemplate.opsForValue().get(Global.REDIS_SEARCH_DEVICE);
        model.addAttribute(Global.REDIS_SEARCH_DEVICE, search_device);
        /* 放入统计信息 */
        Statistics device_statistics = (Statistics) jsonRedisTemplate.opsForValue().get(Global.REDIS_DEVICE_STATISTICS);
        model.addAttribute(Global.REDIS_DEVICE_STATISTICS, device_statistics);
        /* 最后放入所有的分组号 */
        model.addAttribute(Global.REDIS_DEVICE_GROUPNRS,
                (List<Character>) jsonRedisTemplate.opsForValue().get(Global.REDIS_DEVICE_GROUPNRS));

        return "device/list";
    }

}
